package com.xuelang.pipeline.client.pipeline;

import com.xuelang.pipeline.client.common.constant.DictDTO;
import com.xuelang.pipeline.client.common.request.PageParam;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.common.vo.SelectVO;
import com.xuelang.pipeline.client.pipeline.dto.*;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import java.util.List;

/**
 * 流水线服务API
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
public interface IPipelineService {

    /**
     * 查询流水线列表(有过滤条件，可以分页)
     *
     * @param dtoPageParam
     * @return
     */
    @PostMapping(value = "/pageList", produces = "application/json;charset=utf-8")
    ApiResult<PageRecord<PipelineDTO>> pagePipelineList(@RequestBody @Valid PageParam<PipelineQuery> dtoPageParam);

    /**
     * 查询我的流水线列表（有过滤条件）
     * @param dtoPageParam
     * @return
     */
    @PostMapping(value = "/pageMyPipeline", produces = "application/json;charset=utf-8")
    ApiResult<PageRecord<MyPipelineInfoDTO>> pageMyPipelineList(@RequestBody @Valid PageParam<MyPipelineQuery> dtoPageParam);

    /**
     * 查询流水线列表(有过滤条件)
     *
     * @param pipelineQuery
     * @return
     */
    @PostMapping(value = "/list", produces = "application/json;charset=utf-8")
    ApiResult<List<PipelineDTO>> conditionalPipelineList(@RequestBody @Valid PipelineQuery pipelineQuery);

    /**
     * 新增流水线
     *
     * @param pipelineConfigDTO
     * @return
     */
    @PostMapping(value = "", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> addPipeline(@RequestBody @Valid PipelineConfigDTO pipelineConfigDTO);

    /**
     * 更新流水线
     *
     * @param pipelineConfigDTO
     * @return
     */
    @PutMapping(value = "", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> updatePipeline(@RequestBody @Valid PipelineConfigDTO pipelineConfigDTO);

    /**
     * 删除流水线
     *
     * @param code
     * @return
     */
    @DeleteMapping(value = "/{code}", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> deletePipeline(@PathVariable("code") String code);

    /**
     * 查询流水线
     *
     * @param code
     * @return
     */
    @GetMapping(value = "/{code}", produces = "application/json;charset=utf-8")
    ApiResult<PipelineDTO> queryPipeline(@PathVariable("code") String code);

    /**
     * 查询组件流水线信息
     *
     *
     * @param request
     * @param pipelineQuery
     * @return
     */
    @PostMapping(value = "/componentPipeline", produces = "application/json;charset=utf-8")
    ApiResult<ComponentPipelineDTO> queryComponentPipeline(HttpServletRequest request,
                                                           @RequestBody @Valid ComponentPipelineQuery pipelineQuery);

    /**
     * 获取流水线配置信息
     *
     * @param code 流水线编码
     * @return
     */
    @GetMapping(value = "/pipelineConfig/{code}", produces = "application/json;charset=utf-8")
    ApiResult<PipelineConfigDTO> queryPipelineConfig(@PathVariable("code") String code);

    /**
     * 获取指定流水线的webhook触发地址
     *
     * @param pipelineId
     * @param preUri
     * @return
     */
    @GetMapping(value = "/queryPipelineWebhook", produces = "application/json;charset=utf-8")
    ApiResult<String> queryPipelineWebhook(@RequestParam("pipelineId") Long pipelineId,
                                           @RequestParam("preUri") String preUri);


    /**
     * 查询部署任务字典
     *
     * @param
     * @return
     */
    @PostMapping(value = "/deploy/env", produces = "application/json;charset=utf-8")
    ApiResult<List<DictDTO>> queryDeployEnvDict(@RequestBody @Valid DeployCompTaskQuery deployCompTaskQuery);

    /**
     * 查询流水线yaml配置
     *
     * @param
     * @return
     */
    @GetMapping(value = "/yamlConfig/{code}", produces = "application/json;charset=utf-8")
    ApiResult<String> queryDeployYaml(@PathVariable("code") String code);


    /**
     * 任务节点日志下载接口
     * @param envId
     * @param podName
     * @param containerName
     * @param response
     */
    @GetMapping(value = "/pipeline/taskLog/download")
    void downloadTaskLog(@RequestParam("envId") String envId,
                         @RequestParam("podName") String podName,
                         @RequestParam("containerName") String containerName,
                         HttpServletResponse response);

    /**
     * 通过流水线编码查询需要给那些人推送消息
     *
     * @param code
     * @return
     */
    @GetMapping(value = "/findPipelineNotifyReceiverList")
    ApiResult<List<String>> findPipelineNotifyReceiverList(@RequestParam("code") String code);

    /**
     * 获取触发方式枚举下拉选项
     * @return
     */
    @GetMapping(value = "/listTriggerWay", produces = "application/json;charset=utf-8")
    ApiResult<List<SelectVO>> listTriggerWay();

    /**
     * 获取流水线实例状态枚举下拉选项
     * @return
     */
    @GetMapping(value = "/listPipelineInstanceStatus", produces = "application/json;charset=utf-8")
    ApiResult<List<SelectVO>> listPipelineInstanceStatus();
}
